G = input()
l = 0
if len(G) == 4:
    for i in range(0,4):
        for h in range(i+1,5):
            k=int(G[i:h])
            f = 0
            for x in range(1,k+1):
                if k % x == 0:
                    f = f + 1
            if f == 2:
               l = max(l,k)

print(l)
